package lua.compiler.tokens;
import lua.compiler.CompilerException;
import lua.compiler.CtsType;
import lua.compiler.Function;

import org.antlr.runtime.tree.Tree;

public abstract class GenericToken {
	
	private CtsType ctsType = CtsType.OBJECT; 
	private int instructionsCount;
	
	public CtsType getCtsType() {
		return ctsType;
	}

	public void setCtsType(CtsType ctsType) {
		this.ctsType = ctsType;
	}
	
	public int getInstructionsCount() {
		return instructionsCount;
	}

	/***
	 * Tworzy kod w CIL dla konkretnego tokena
	 * @param tree Drzewo ktore przeksztalcamy na CIL
	 * @param function funkcja do ktorej nalezy parsowany kod
	 */
	public void parse(Tree tree, Function function) throws CompilerException {
		int funcInstructionsCountBefore = function.getInstructionsCount();
		parseImpl(tree, function);
		instructionsCount = function.getInstructionsCount() - funcInstructionsCountBefore;
	}
	protected abstract void parseImpl(Tree tree, Function function) throws CompilerException;
}
